package com.ltmt.es.utils.csvparser;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.ltmt.es.utils.exceptions.CSVParseException;


import au.com.bytecode.opencsv.CSVReader;

public class CSVUtils {
	
	public List<String[]> parseCSV(String csvFile) throws CSVParseException{
		
		List<String[]> lst = new ArrayList<String[]>();
		try {
			CSVReader reader = new CSVReader(new FileReader(csvFile), ';');
			String [] nextLine;
			while ((nextLine = reader.readNext()) != null) {
				// nextLine[] is an array of values from the line
				lst.add(nextLine);
			}
			reader.close();
		} catch (FileNotFoundException fnfex){
			throw new CSVParseException(fnfex.getMessage(), fnfex);
		} catch (IOException ioex) {
			throw new CSVParseException(ioex.getMessage(), ioex);
		} catch (Exception ex){
			throw new CSVParseException(ex.getMessage(), ex);
		} finally {
			
		}
		return lst;	
	}
}
